package com.lanou3g.code0523;

import com.sun.deploy.net.HttpRequest;
import com.sun.tools.javac.jvm.Code;
import org.omg.CORBA.Request;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class FirstFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //初始化方法,作用等同于servlet的init方法

    }

    @Override
    public void doFilter(ServletRequest servletRequest,
                         ServletResponse servletResponse,
                         FilterChain filterChain) throws IOException, ServletException {

        servletRequest.setCharacterEncoding("utf-8");
        servletResponse.setContentType("text/html;charset=utf-8");
        //每次执行过滤的时候  调用的方法
        //放行这次请求
        HttpServletRequest req= (HttpServletRequest) servletRequest;

        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
        //当filter销毁的时候,会调用的方法

    }
}
